package com.hc.oa.assertion.service;

import java.util.Collection;
import java.util.Map;

import javax.annotation.Resource;

import org.hibernate.annotations.common.util.StringHelper;
import org.hibernate.criterion.DetachedCriteria;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.bstek.dorado.annotation.DataProvider;
import com.bstek.dorado.annotation.DataResolver;
import com.bstek.dorado.data.provider.Criteria;
import com.bstek.dorado.data.provider.Page;
import com.bstek.dorado.hibernate.HibernateUtils;
import com.hc.oa.assertion.dao.AssertionDao;
import com.hc.oa.attendance.dao.AttendancemanagerDao;
import com.hc.oa.model.Bdf2Assertion;
import com.hc.oa.model.SlAttendance;


@Component("AssertionmanagerService")
public class AssertionmanagerService {
	 @Resource
	    private AssertionDao AttendancemanagerDao;
	     
	    @DataProvider
	    public Collection<Bdf2Assertion> getAll(){
	        return AttendancemanagerDao.getAll();
	    }
	     
	    @DataProvider
	    public void getAllForPage(Page<Bdf2Assertion> page,Map<String, Object> parameter) throws Exception{
	        AttendancemanagerDao.queryAllByAssertPage(page,Bdf2Assertion.class,parameter);
	    }
	    
	    @DataResolver
	    @Transactional
	    public void saveSlAttendance(Collection<Bdf2Assertion> datas) {
	    	AttendancemanagerDao.persistEntities(datas);
		}
	    
	    @DataProvider
	    public void getAllForFilter(Page<Bdf2Assertion> page, Criteria criteria) throws Exception{
	        DetachedCriteria detachedCriteria = DetachedCriteria.forClass(Bdf2Assertion.class);
	        if (criteria != null){
	            AttendancemanagerDao.find(page, HibernateUtils.createFilter(detachedCriteria, criteria));
	        }else{
	        	AttendancemanagerDao.getAll(page);
	        }
	    }
	     
	    @DataProvider
	    public void queryForCondition(Page<Bdf2Assertion> page, Map<String, Object> params) {
	        if (null != params) {
	        	String Assert_name = (String)params.get("Assert_name");
	            String Assert_people = (String)params.get("Assert_people");
	            String Assert_status = (String) params.get("Assert_status");
	            String Assert_type = (String)params.get("Assert_type");
	            String Assert_inputpeople = (String)params.get("Assert_inputpeople");
	            String Assert_inputdate = (String)params.get("Assert_inputdate");
	            String Assert_returndate = (String)params.get("Assert_returndate");
	            String whereCase = "";
	            if (StringHelper.isNotEmpty(Assert_name)) {
	                whereCase += " AND Assert_name '%" + Assert_name + "%' ";
	            }
	            
	            if (StringHelper.isNotEmpty(Assert_people)) {
	                whereCase += " AND Assert_people '%" + Assert_people + "%' ";
	            }
	             
	            if (StringHelper.isNotEmpty(Assert_status)) {
	                whereCase += " AND Assert_status '%" + Assert_status + "%' ";
	            }
	             
	            if (StringHelper.isNotEmpty(Assert_type)) {
	                whereCase += " AND Assert_type '%" + Assert_type + "%' ";
	            }
	             
	            if (StringHelper.isNotEmpty(Assert_inputpeople)) {
	                whereCase += " Assert_inputpeople '%" + Assert_inputpeople + "%' ";
	            }
	             
	            if (StringHelper.isNotEmpty(Assert_inputdate)) {
	                whereCase += " ATTENDANCE_DATE '%" + Assert_inputdate + "%' ";
	            }
	            	            
	            if (StringHelper.isNotEmpty(Assert_returndate)) {
	                whereCase += " Assert_returndate '%" + Assert_returndate + "%' ";
	            }

	            AttendancemanagerDao.find(page, " from SlAttendance where 1=1 " + whereCase);
	        } else
	            AttendancemanagerDao.getAll(page);
	    }
}
